//package com.example.demo.actions;
//
//import com.example.demo.services.DependencyAnalyzerService;
//import com.example.demo.utils.GraphvizUtils;
//import com.intellij.openapi.actionSystem.AnAction;
//import com.intellij.openapi.actionSystem.AnActionEvent;
//import com.intellij.openapi.project.Project;
//import com.intellij.openapi.ui.Messages;
//import com.intellij.openapi.vfs.VirtualFile;
//
//import java.nio.file.Path;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Set;
//
//public class AnalyzeJarDependenciesAction extends AnAction {
//    @Override
//    public void actionPerformed(AnActionEvent e) {
//        Project project = e.getProject();
//        if (project == null) {
//            Messages.showErrorDialog("No project found!", "Error");
//            return;
//        }
//
//        VirtualFile baseDir = project.getBaseDir();
//        if (baseDir == null) {
//            Messages.showErrorDialog("No project base directory found!", "Error");
//            return;
//        }
//
//        DependencyAnalyzerService analyzerService = new DependencyAnalyzerService();
//        try {
//            Map<String, Map<String, Set<String>>> methodDependencies = analyzerService.analyzeProjectDependencies(Path.of(baseDir.getPath()));
//            Map<String, Set<String>> classDependencies = analyzerService.extractClassLevelDependencies(methodDependencies);
//            Map<String, Set<String>> jarDependencies = analyzerService.extractJarLevelDependencies(classDependencies);
//
//            Map<String, Map<String, Set<String>>> dependencies = new HashMap<>();
//            jarDependencies.forEach((className, deps) -> {
//                Map<String, Set<String>> dummy = new HashMap<>();
//                dummy.put("JarLevel", deps);
//                dependencies.put(className, dummy);
//            });
//
//            String outputPath = baseDir.getPath() + "/jar_dependencies.png";
//            GraphvizUtils.generateGraph(dependencies, outputPath, "Jar Level Dependencies");
//            Messages.showInfoMessage("Jar dependencies graph generated at " + outputPath, "Success");
//        } catch (Exception ex) {
//            Messages.showErrorDialog("Failed to analyze jar dependencies: " + ex.getMessage(), "Error");
//        }
//    }
//}
